<template>
  <div>
    <el-dialog title="新增银行" :visible.sync="showAddBankDialog" center width="700px">
      <el-form :model="bankData" ref="bankData" :rules="rules">

        <el-form-item label="银行名称" :label-width="formLabelWidth" prop="name">
          <el-input v-model="bankData.name" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="状态" :label-width="formLabelWidth">
          <!-- label为选定时候的值 -->
          <el-radio v-model="bankData.status" :label="0">停用</el-radio>
          <el-radio v-model="bankData.status" :label="1">启用</el-radio>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog">取 消</el-button>
        <el-button type="primary" @click="submitBank('bankData')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import store from '@/store'
  import {add} from '@/api/thk/cms/bank'

  export default {
    name: 'addBank',
    data() {
      return {
        showAddBankDialog: false,
        formLabelWidth: '130px',
        bankData: {
          name: '',
          status: 1
        },

        rules: {
          // 主行名字必须
          name:[
            { required: true, message: '请输入主行名称', trigger: 'blur' },
          ],
        }
      }
    },


    methods: {
      // 点击提交校验数据
      submitBank(bankData){

        this.$refs[bankData].validate((valid) => {

          if (valid) {
            add(store.getters.token,this.bankData).then(result => {
              // 增加成功
              this.showAddBankDialog = !this.showAddBankDialog
              this.$parent.getBankList()
            }).catch(error => {
              console.log(error)
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },

      cancelDialog(){
        this.showAddBankDialog = !this.showAddBankDialog
      }

    }
  }
</script>
